package cn.santi.controller;

import cn.santi.domain.StaffUrlpath;
import cn.santi.emuns.R;
import cn.santi.service.StaffUrlpathService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@RestController
@RequestMapping("/urlpath")
public class UrlpathControoler {

    @Autowired
    private StaffUrlpathService su;
    //添加图片
    @GetMapping("/addurlpath")
    public R addurlpath(StaffUrlpath st){
        return R.ok(su.save(st));
    }
    //删除图片路径
    @GetMapping("/delurlpath")
    public R delurlpath(String imgpath) throws IOException {
        QueryWrapper<StaffUrlpath> wrapper = new QueryWrapper<>();
        wrapper.eq("urlpath","state/images/"+imgpath);
        boolean b = su.remove(wrapper);
        Path path = Paths.get("E://hbx/"+imgpath);
        Files.delete(path);
        return R.ok(b);
    }
    //显示图片图集
    @GetMapping("/showurllist")
    public R showurllist(int id){
        QueryWrapper<StaffUrlpath> wrapper = new QueryWrapper<>();
        wrapper.eq("sid",id);
        return R.ok(su.list(wrapper));
    }
}
